/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __XOS_ODBC_ODBC_FIELD_H__
#define __XOS_ODBC_ODBC_FIELD_H__

#include "../tools/head.h"
#include "include_odbc.h"
#include "i_stmt.h"

namespace xos_odbc
{

    class odbc_field : public xos_stl::mem_item< xos::release_impl< odbc_field >, thread_lock >
    {
    public:
        typedef xos::release_impl< odbc_field > T;

    public:
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // 
        static int get_xos_item_data( ITEM_DATA*& item_ptr );

    public:
        odbc_field();
        ~odbc_field();

    public:
        xos_box::i_wstring * m_pStringW;
        xos_box::i_string * m_pStringA;
        xos_box::i_buf * m_pBuf;

        i_stmt::enumValueType m_eType;
        std::string m_name;
        int m_nDigitnum;
        int m_nBufSize;
        int m_nIndex;

        intptr_t len_or_ptr;
        bool m_bIsKey;
        bool m_bDirty;

        union{
            int64_t * i64_ptr;
            int32_t * i32_ptr;
            int16_t * i16_ptr;
            int8_t * i8_ptr;
            uint64_t * u64_ptr;
            uint32_t * u32_ptr;
            uint16_t * u16_ptr;
            uint8_t * u8_ptr;
            wchar_t * wchar_ptr;
            double * double_ptr;
            float * float_ptr;
            bool * bool_ptr;
        };

        union{
            int64_t i64_v;
            int32_t i32_v;
            int16_t i16_v;
            int8_t i8_v;
            uint64_t u64_v;
            uint32_t u32_v;
            uint16_t u16_v;
            uint8_t u8_v;
            double double_v;
            float float_v;
            bool bool_v;
        };

    protected:
        xos_box::i_string * m_pOwnerStringA;

    public:
        int set_type( i_stmt::enumValueType eType, int nSize, int nDigitNum );
        int set_name( const char * lpszName );

        int set_string( const char * lpszName, xos_box::i_string * lpData );

        int set_float_digit_num( int nNum );

        int bind_param( i_stmt * pStmtI );
        int bind_col( i_stmt * pStmtI );

        int get_str_from_buf();
        int set_str_to_buf();

        int clear_value();

    protected:
        int init_data();

    public:
        int init();
        int term();
    };

} // xos_odbc

#endif // __XOS_ODBC_ODBC_FIELD_H__
